package com.JVM核心机制;

/**
 * 静态方法加载时，从上往下加载
 *
 * @author jiangbang
 * @date 2016/9/20
 */
public class Demo01 {
    public static void main(String[] args) {
        A a = new A();
        System.out.println(A.width);
        B b = new B();
        System.out.println(b.width);

        System.out.println("##########");
        System.out.println("demo01的main方法");
        C C = new C();
        C C2 = new C();
    }
}

//加载时，从上往下加载
class A {
        public static int width=100;
        static{
            System.out.println("静态初始化类A");
            width=300;
        }
        public A(){
            System.out.println("创建A类的对象");
        }

}

class B {
    static{
        System.out.println("静态初始化类B");
        width=300;
    }

    public static int width=100;

    public B(){
        System.out.println("创建B类的对象");
    }

}


class C extends C_Father{
    public static int width=100;
    static{
        System.out.println("静态初始化类C");
        width=300;
    }
    public C(){
        System.out.println("创建C类的对象");
    }

}

class C_Father{
    static{
        System.out.println("静态初始化类C_Father");
    }
}
